package controllers;

import beans.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import services.ContactServices;
import services.ContractServices;
import services.impl.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginControllers {
    @Autowired
    private UserServicesImpl usi;
    @Autowired
    private AftersalesLogServicesImpl aftersalesLogServices;
    @Autowired
    private BusinessInformationServicesImpl businessInformationServices;
    @Autowired
    private ContactServices contactServices;
    @Autowired
    private ContractServices contractServices;
    @Autowired
    private EmployeeServiceImpl employeeService;
    @Autowired
    private LogServicesImpl logServices;
    @Autowired
    private OrderServicesImpl orderServices;
    @Autowired
    private OrganServicesImpl organServices;
    @Autowired
    private ProductServicesImpl productServices;
    @Autowired
    private ProfileServiceImpl profileService;
    @Autowired
    private SlilServicesImpl slilServices;


    @RequestMapping("/login")
    public int login(@RequestBody User user){
        int i ;
        Map<String, String> map = new HashMap<>();
        String userId = user.getUserId();
        String userPassword = user.getUserPassword();
        if (usi.login(userId,userPassword)!=null){
            i=1;
        }else {
            i=-1;
        }
            return i;
    }

    @RequestMapping("/index")
    public Map<String, Integer> index(){
        Map<String, Integer> map = new HashMap<>();
        int afterSalesLog = aftersalesLogServices.count();
        int business = businessInformationServices.count();
        int contact = contactServices.count();
        int contract = contractServices.count();
        int employee = employeeService.count();
        int log = logServices.count();
        int order = orderServices.count();
        int organ = organServices.count();
        int product = productServices.count();
        int profile = profileService.count();
        int sili = slilServices.count();
        map.put("afterSalesLogCount",afterSalesLog);
        map.put("businessCount",business);
        map.put("contactCount",contact);
        map.put("contractCount",contract);
        map.put("employCount",employee);
        map.put("logCount",log);
        map.put("orderCount",order);
        map.put("organCount",organ);
        map.put("productCount",product);
        map.put("profileCount",profile);
        map.put("siliCount",sili);
        return map;
    }
}
